using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.System;


namespace HengTong.ViewModel.Common.SysTemplateVms
{
    public partial class SysTemplateListVm : BasePagedListVM<SysTemplateView, SysTemplateSearcher>
    {

        protected override IEnumerable<IGridColumn<SysTemplateView>> InitGridHeader()
        {
            return new List<GridColumn<SysTemplateView>>{
                this.MakeGridHeader(x => x.TemplateName),
                this.MakeGridHeader(x => x.TemplateCode),
                this.MakeGridHeader(x => x.TemplateType),
                this.MakeGridHeader(x => x.TemplateContent),
                this.MakeGridHeader(x => x.Status),
                this.MakeGridHeader(x => x.Version),
                this.MakeGridHeader(x => x.Remarks),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysTemplateView> GetSearchQuery()
        {
            var query = DC.Set<SysTemplate>()
                .CheckEqual(Searcher.TemplateType, x=>x.TemplateType)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .Select(x => new SysTemplateView
                {
				    ID = x.ID,
                    TemplateName = x.TemplateName,
                    TemplateCode = x.TemplateCode,
                    TemplateType = x.TemplateType,
                    TemplateContent = x.TemplateContent,
                    Status = x.Status,
                    Version = x.Version,
                    Remarks = x.Remarks,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysTemplateView : SysTemplate{

    }
}
